Skip to content

Conversation

gibson042
Copy link
Member

Includes #4545
Ref #4509

%TypedArray% instance operations

  • [[GetOwnProperty]]

    • property descriptors for in-bounds indexes of a typed array backed by an immutable ArrayBuffer are reported as writable false, enumerable true, configurable false
  • [[DefineOwnProperty]]

    • attempts to redefine own properties for in-bounds indexes of a typed array backed by an immutable ArrayBuffer are validated against descriptors for immutable properties
      • presence of writable: true, enumerable: false, configurable: true, get, and/or set results in rejection
      • presence of value with any value that is not treated as identical to the current value by Object.is results in rejection (e.g., value: -0 and value: "0" are rejected when the current value is 0)
      • all other property descriptors (e.g., any subset of { writable: false, enumerable: true, configurable: false, value: $currentValue }) are accepted but do not result in observable changes
  • [[Set]]

    • any attempt to set the value for a property whose name is a canonical numeric index string (including non-index values such as "-0", "1.5", "590295810358705700000", "5e-324", "1.7976931348623157e+308", "Infinity", and "NaN") on a typed array backed by an immutable ArrayBuffer is rejected, even if the new value is identical to the current value
    • likewise for attempts on a receiver having such a typed array in its prototype chain when the [[Set]] makes it to the typed array

gibson042 added 28 commits July 23, 2025 12:10
With `sedi` being a portable `sed -i`, e.g. `sed -i '' "$@"` on BSD and
`sed -i "$@"` on Linux:
```sh
git grep -l 'testWith[A-Za-z]*TypedArrayConstructors[(].*, N.*' test/built-ins/ | \
  xargs sedi -E 's#(testWith[A-Za-z]*TypedArrayConstructors[(].*), N([^a-zA-Z].*)#\1\2#'
```
With `sedi` being a portable `sed -i`, e.g. `sed -i '' "$@"` on BSD and
`sed -i "$@"` on Linux:
```sh
git grep -l 'testBigIntTypedArray[.]js' | \
  xargs sedi 's#testBigIntTypedArray[.]js#testTypedArray.js#'
```
…uctors

With `sedi` being a portable `sed -i`, e.g. `sed -i '' "$@"` on BSD and
`sed -i "$@"` on Linux:
```sh
git grep -l 'testWith[A-Za-z]*TypedArrayConstructors[(]' test/built-ins/ | \
  while read f; do
    grep -qF detachArrayBuffer.js "$f" && continue
    grep -qF '.resize(' "$f" && continue
    taCtorAliases="$(sed -nE \
      's#testWith[A-Za-z]*TypedArrayConstructors[(] *(function[^(]*[(] *|[^a-zA-Z0-9_]*)([a-zA-Z0-9_]+).*#\2#p' \
      "$f")"
    sedi -E '
      s#(testWith[A-Za-z]*TypedArrayConstructors[(] *(function[^(]*[(] *|[(] *)[a-zA-Z0-9_]+)#\1, makeCtorArg#; t;
      s#(testWith[A-Za-z]*TypedArrayConstructors[(] *)([a-zA-Z0-9_]+)#\1(\2, makeCtorArg)#; t;
      '"$(printf '%s' "$taCtorAliases" | sed -E 's/(.*)/s#\\b\1[(]([0-9.]+n?|[[][^]]*[]])[)]#\1(makeCtorArg(\\1))#/')" \
      "$f"
  done

git diff --numstat -- test/built-ins/ | \
  awk '{ print $NF }' | \
  xargs grep -c '\bmakeCtorArg\b' | \
  sed -n 's/:1$//p' | \
  xargs sedi -E '
    /makeCtorArg/,$ { s#^[}][)]#}, null, ["passthrough"])#; }
    /makeCtorArg/ { s#, makeCtorArg##; s#[(]([a-zA-Z0-9_]+)[)] =>#\1 =>#; }
  '

git diff --numstat -- test/built-ins/ | \
  awk '{ print $NF }' | \
  xargs grep -l '\bdefineProperty\b' | \
  xargs sedi -E \
    '/testWith[A-Za-z]*TypedArrayConstructors[(]/,$s#^[}][)]#}, null, ["passthrough"])#'
```
…e contents

With `sedi` being a portable `sed -i`, e.g. `sed -i '' "$@"` on BSD and
`sed -i "$@"` on Linux:
```sh
git grep -l 'testWith[A-Za-z]*TypedArrayConstructors[(]' \
    test/built-ins/TypedArray/prototype/{copyWithin,fill,reverse,set,sort} | \
  xargs sedi -E \
    '/testWith[A-Za-z]*TypedArrayConstructors[(]/,$s#^[}][)]#}, null, null, ["immutable"])#'

git grep -l 'testWith[A-Za-z]*TypedArrayConstructors[(]' \
    test/built-ins/TypedArray/prototype | \
  grep -E 'set-value-during-|predicate-call-changes-value|values-are-not-cached' | \
  xargs sedi -E \
    '/testWith[A-Za-z]*TypedArrayConstructors[(]/,$s#^[}][)]#}, null, null, ["immutable"])#'
```
…perties cannot be set when the backing buffer is immutable
…es are non-configurable and non-writable when the backing buffer is immutable
@gibson042 gibson042 requested a review from a team as a code owner July 29, 2025 16:35
…es being defined are validated against descriptors for immutable properties
@gibson042 gibson042 force-pushed the 2025-07-immutable-arraybuffer-typedarray-internal-operations branch from 55e9cb7 to 795f516 Compare August 1, 2025 01:35
var value1 = sample[1];
assert.compareArray([String(value0), String(value1)], ["42", "43"]);

verifyProperty(sample, "0", {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that verifyProperty() is based on various assumptions that don't work for typed arrays. For example, isWritable(new Uint8Array(8), "0") is false (incorrectly) and isWritable(new BigInt64Array(8), "0") even results in SyntaxError: Cannot convert unlikelyValue to a BigInt.

The current version of the test seems to be lucky to pass despite the usage of verifyProperty(), but it is probably better to avoid it (for typed arrays). Note that, for example, index-prop-desc.js that is kind of mutable version of this test avoids verifyProperty() for the mentioned reasons.

includes: [testTypedArray.js, compareArray.js, propertyHelper.js]
---*/

testWithAllTypedArrayConstructors(function(TA, makeCtorArg) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other tests in the same directory do not test BigInt typed arrays i.e. use testWithTypedArrayConstructors instead of testWithAllTypedArrayConstructors (and contain a variant with testWithBigIntTypedArrayConstructors in BigInt sub-directory).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants